package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.PermissionDao;

import com.itheima.entity.PageResult;

import com.itheima.pojo.Permission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    PermissionDao permissionDao;

    @Override
    public List<Permission> findAll() {
        return permissionDao.findAll();
    }

    @Override
    public PageResult findByPage(Integer pageSize, Integer currentPage, String queryString) {
        PageHelper.startPage(currentPage,pageSize);
        Page<Permission> page=permissionDao.findByPage(queryString);
        return new PageResult(page.getTotal(),page);
    }

    @Override
    public void add(Permission permission) {
         permissionDao.add(permission);
    }

    @Override
    public Permission findById(Integer id) {
        return permissionDao.findById(id);
    }

    @Override
    public void update(Permission permission) {
        permissionDao.update(permission);
    }

    @Override
    public void delById(Integer id) {
        permissionDao.deletePermissionandRoleAssociation(id);
        permissionDao.delById(id);
    }


}
